import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Random;


public class Problemcase
{

	private int id;
	private String department;
	private String gender;
	private GregorianCalendar date;
	private GregorianCalendar starttime;
	private GregorianCalendar endtime;
	private long duration;
	private int productID;
	private int importance;
	private String problemsolved;
	
	public Problemcase()
	{
		setId();
		setDepartment();
		setGender();
		setDate();
		setStartTime();
		setEndTime();
		setDuration();
		setProductID();
		setImportance();
		setProblemsolved();
	}
	
	public void setId()
	{
		this.id = (int) (Math.random()*10000);
	}
	
	public int getId()
	{
		return id;
	}
	
	
	public void setDepartment()
	{
		//4 departmentes: accounting, logistics, secretariat, human resources 
		
		int d = (int) (Math.random()*100);
		
		if(d <= 65) this.department = "accounting"; 
		else if(d <= 80) this.department = "logistics";
		else if(d <= 93) this.department = "marketing";
		else if(d <= 100) this.department = "human res.";	
	}
	
	public String getDepartment()
	{
		return department;
	}
	
	public void setGender()
	{
		int g = (int) (Math.random()*100);
		
		if(g <= 70) this.gender = "w";
		else this.gender = "m";
	}
	
	public String getGender()
	{
		return gender;
	}
	
	public void setDate()
	{
		GregorianCalendar g = new GregorianCalendar();
		Random r = new Random();
		int y = 0;
		int m = 0;
		int d = 0;
		
		int year = (int) (Math.random()*10);
		if (year <= 6) y = 2011;
		else if (year <= 8) y = 2010;
		else if (year <= 10) y = 2009;
		
		m = (r.nextInt(12 - 1)+1);
		
		if(m == 2) d = r.nextInt(28);
		d = r.nextInt(31);	
		
		g.set(y, m, d);
		this.date = g;
	}
	
	public Calendar getDate()
	{
		return date;
	}
	
	@SuppressWarnings("deprecation")
	public void setStartTime()
	{
		GregorianCalendar c = new GregorianCalendar();
		Random r = new Random();
		Date d = new Date();
		
		//zahl zwischen 7 und 18 (uhr)
		d.setHours(r.nextInt(18 - 7) + 7);
		d.setMinutes(r.nextInt(59));
		
		c.setTime(d);
		this.starttime = c;
		
	}
	
	public Calendar getStartTime()
	{
		return starttime;
	}
	
	public void setEndTime()
	{
		GregorianCalendar c = new GregorianCalendar();
		long start = getStartTime().getTimeInMillis();
		long end = start + (long) (Math.random()*800000);
		
		c.setTimeInMillis(end);
		this.endtime = c;
	}
	
	public Calendar getEndTime()
	{
		return endtime;
	}
	
	public void setDuration()
	{
		duration = (endtime.getTime().getTime() - starttime.getTime().getTime()) / 1000;
	}
	
	public void setProductID()
	{
		// 10 Produkte
		int p = (int) (Math.random()*10);
		
		if(p == 0)this.productID = 1;
		else this.productID = p;
	}
	
	public int getProductID()
	{
		return productID;
	}
	
	public void setImportance()
	{
		int i = (int) (Math.random()*100);
		
		if(i <= 60) this.importance = 1;
		else if(i <= 70) this.importance = 2;
		else if(i <= 80) this.importance = 3;
		else if(i <= 95) this.importance = 4;
		else if(i <= 100) this.importance = 5;
	}
	
	public int getImportance()	
	{
		return importance;
	}
	
	public void setProblemsolved()
	{
		int ps = (int) (Math.random()*100);
		
		if(ps <= 95) this.problemsolved = "y";
		else this.problemsolved = "n";
	}
	
	public String getProblemsolved()
	{
		return problemsolved;
	}
	
	
	public String toString()
	{
		String d = String.valueOf(date.get(Calendar.YEAR)) + "." + String.valueOf(date.get(Calendar.MONTH)) + "." + String.valueOf(date.get(Calendar.DATE));
		return String.format("caller ID: %d\t department: %s\t gender: %s\t date: %s \t starttime: %tr\t endtime: %tr\t duration: %d sec\t product ID: %d\t importance: %d\t problemsolved: %s\t \n", id, department, gender, d, starttime, endtime, duration, productID, importance, problemsolved);
	}
	
	
	
}
